package com.hjb.service.utils;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SendSmsUtil {

	private static Logger log = LoggerFactory.getLogger(SendSmsUtil.class);
	
	private final static String account = "jixingtou";
//	private final static String password = "jixingtou";
	private final static String password = "b059cf8406059fd44b1358000c5909a0";
	private final static String url = "http://open.96xun.com/Api/SendSms?";
	
	public static String sendSms(String phone,String content){
		String result ="";
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("Uname", account);
			params.put("Upass",password);
			params.put("Mobile", phone);
			params.put("Content", "【住分期】"+URLEncoder.encode(content, "UTF-8"));
	//		params.put("mobileAndContent", "17600901605|您的验证码是：666666");
	//		params.put("mobileAndContent", "13581648587|您的验证码是：555555");
		
			result = PostUtil.sendPost(url, params, "UTF-8");
			JSONObject jsonObj = JSONObject.fromObject(result);
			System.out.println(jsonObj.get("Status"));
			String resCode = jsonObj.getString("Status");
			if(StringUtils.isNotBlank(resCode) && "1".equals(resCode)){
				log.info("发送验证码成功：code:"+resCode+",phone："+phone+",内容："+content);
			} else{
				log.info("发送验证码失败：code:"+resCode+"msg:"+jsonObj.getString("msg")+",phone："+phone+",内容："+content);
			}
			
		} catch (Exception e) {
			log.info(e.getMessage());
		}
		return result;
	}
	
}
